﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using com.dz.common;
using com.dz.components;
namespace com.dz.web.admin
{
    public partial class bookCommendList : BasePage
    {
        int pageIndex = 1;
        int pageSize = 20;
        int totalCount = 0;
        int commendType = -1;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!int.TryParse(Request["commendType"], out commendType))
                commendType = -1;
            if (!int.TryParse(Request["pageIndex"], out pageIndex))
                pageIndex = 1;
            if (!int.TryParse(Request["totalCount"], out totalCount))
                totalCount = 0;
            drpCommendType.SelectedValue = commendType.ToString();
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            BookCommendManager t_book_commend = new BookCommendManager();
            DataSet ds = t_book_commend.GetCommendListByPage(pageIndex, pageSize, out totalCount, (Consts.CommendType)commendType, Consts.PageType.OutTotalCount);
            if (ds != null && ds.Tables.Count > 0)
            {
                rptBookList.DataSource = ds.Tables[0];
                rptBookList.DataBind();
                lblPageHtml.Text = GetPageHtml(pageIndex, pageSize, totalCount, string.Format("bookCommendList.aspx?commendType={0}&bookName={1}&pageIndex=",
                   commendType, totalCount));
            }
        }

        protected string GetBookImg(string bookId, string bookName, object isExistImage, string categoryName, string subCategoryName)
        {
            bool t_is_exist_image = false;
            if (!bool.TryParse(isExistImage.ToString(), out t_is_exist_image))
                t_is_exist_image = false;
            if (t_is_exist_image == false)
            {
                return string.Format("<img src='/bookImage/0.jpg' border='0' /><br>[{0}]-[{1}]<br>{2}", categoryName, subCategoryName, bookName);
            }
            return string.Format("<img src='/bookImage/{0}.jpg' border='0' /><br>[{1}]-[{2}]<br>{3}", bookId, categoryName, subCategoryName, bookName);
        }
    }
}
